home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9836 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: rcp6.elan.af.mil!rscernix!danpop
  2. From: danpop@mail.cern.ch (Dan Pop)
  3. Newsgroups: comp.sources.wanted,comp.lang.c,comp.unix.programmer
  4. Subject: Re: Seek unix2dos.c OR help with tr
  5. Date: 11 Mar 96 11:59:37 GMT
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <danpop.826545577@rscernix>
  8. References: <4i0946$7io@nuke.csu.net>
  9. NNTP-Posting-Host: ues5.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11.  
  12. In <4i0946$7io@nuke.csu.net> mclean@futon.SFSU.EDU (Emmett Mclean) writes:
  13.  
  14. >Does anyone have the source to a program
  15. >converting a unix file into dos format?
  16. >That is, each decimal 10 char is replaced
  17. >with a series of a 10 and 13.
  18.  
  19. Thinking and programming in terms of magic numbers is a bad idea.
  20. Someone who is less familiar with the ASCII character set won't be able 
  21. to make any sense out of your code.  A program which will replace '\n'
  22. by the '\r' '\n' sequence will be considerably more readable, even if
  23. portability is not a concern (both DOS and Unix use the ASCII character
  24. set).
  25.  
  26. >The equivalent syntax to tr would be fine
  27. >as well.
  28.  
  29. As far as I know, tr can replace characters, can drop characters but
  30. cannot insert characters.
  31.  
  32. >I will be using it to download zipped binaries
  33. >files from a unix box.
  34.  
  35. Then, you DON'T want to touch any character in the file.  The conversion
  36. makes sense only for TEXT files and is guarantee to turn a binary file
  37. into complete garbage.
  38.  
  39. >Ah, writing the program is a bit trickier
  40. >than the little program below since the
  41. >program exits prematurely because getchar reads
  42. >EOF from its input - before getting to
  43. >the real EOF.
  44.  
  45. This is because your implementation is brain dead and you didn't bother
  46. to read the FAQ.
  47.  
  48. OTOH, if the file contains a character which compares equal to EOF,
  49. that file is _probably_ not a text file and it makes little sense to 
  50. pass it through your filter.
  51.  
  52. Dan 
  53. --
  54. Dan Pop
  55. CERN, CN Division
  56. Email: danpop@mail.cern.ch 
  57. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  58.